<div class="layuimini-main">

    <form class="layui-form layuimini-form" id="addTriggerForm" style="text-align:center">



        <div class="layui-form-item">

            <label class="layui-form-label required">料口编号:</label>
            <div class="layui-input-block">
                <input type="text" name="id" lay-verify="required|checkonly" placeholder="请输入料口编号(只能为英文或者-_组成)" value="" class="layui-input">
            </div>

        </div>
        <div class="layui-form-item">

            <label class="layui-form-label required">料口名称</label>
            <div class="layui-input-block">
                <input type="text" name="portName" placeholder="请输入料口名称" class="layui-input">
            </div>

        </div>




        <div class="layui-form-item">

            <label class="layui-form-label required">X坐标值:</label>
            <div class="layui-input-block">
                <input type="number" name="xPosition" lay-verify="required" placeholder="请输入所在区域" data-prec="2" class="layui-input layui-input-number">
            </div>

        </div>
        <div class="layui-form-item">

            <label class="layui-form-label required">Y坐标值:</label>
            <div class="layui-input-block">
                <input type="number" name="yPosition" lay-verify="required" placeholder="请输入所在区域" data-prec="2" class="layui-input layui-input-number">
            </div>

        </div>

        <div class="layui-form-item">

            <label class="layui-form-label required">位置编号:</label>
            <div class="layui-input-block">
                <input type="text" name="locationNumber" lay-verify="required" placeholder="请输入所在的位置编号" value="" class="layui-input">
            </div>

        </div>

        <div class="layui-form-item">

            <label class="layui-form-label">所在区域:</label>
            <div class="layui-input-block">
                <input type="text" name="region" placeholder="请输入所在区域" value="" class="layui-input">
            </div>

        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">所在楼层:</label>
            <div class="layui-input-block">
                <input type="number" name="floor" placeholder="请输入所在楼层" value="" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">

            <div class="layui-input-block">
                <button class="layui-btn layui-btn-normal" lay-submit lay-filter="saveBtn">确认保存</button>
            </div>

        </div>
    </form>
</div>
<script>
    layui.use(['form', 'table'], function () {
        var form = layui.form,
            layer = layui.layer,
            table = layui.table,
            $ = layui.$;
        form.render();
        form.verify({
            checkonly: function (value) {
                var checkResult = "";
                $.ajax({
                    url: "api/ports/Check/id=" + value,
                    type: "get",
                    async: false,
                    success: function (result) {
                        if (result.data > 0) {
                            checkResult = "该ID已经被占用!";
                        }
                    },
                    error: function () {
                        checkResult = "验证出错!";
                    }
                });
                return checkResult;
            }
        });
      
        //监听提交
        form.on('submit(saveBtn)', function (data) {
            var deviceId = $("#mDevice").val();
         
            $.ajax({
                url: 'api/ports/Create',
                method: 'post',
                contentType: 'application/json; charset=utf-8',
                cache: false,
                data: JSON.stringify(data.field),
                success: function (res) {

                    if (res.code === 200) {
                        var index = layer.confirm('添加成功!是否继续添加?', {
                            btn: ['是', '否'],
                            yes: function () {

                                layer.close(index);
                                $("#addTriggerForm")[0].reset();
                                layui.form.render();
                            },
                            btn2: function () {
                                layer.closeAll();
                            }
                        });
                    }
                    else
                        layer.msg('添加失败!', { icon: 2 });
                },
                error: function (data) {
                    layer.msg('添加出错!', { icon: 2 });

                }
            });

            return false;
        });


    });</script>